//import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

// export const useCounterStore = defineStore('counter', () => {
//   const count = ref(0)
//   const doubleCount = computed(() => count.value * 2)
//   function increment() {
//     count.value++
//   }

//   return { count, doubleCount, increment }
// })

export const useCounter = defineStore('counter', {
  state: () => {
    return {
      num: 1,
      token: 'af8a90f8a09fa09f',
      username: '张三',
      arr: [3, 4, 5, 7, 88]
    }
  },
  actions: {
    add(v) {
      this.num += v
    }
  },
  getters: {
    total(state) {
      return state.arr.reduce((acc, cur) => acc + cur, 0)
    }
  },
  //数据持久化
  persist: {
    storage: window.sessionStorage
  }
})
